/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mp.health.model;

import com.mp.appApi.database.HibernateUtils;
import com.mp.appApi.util.FileUtils;
import com.mp.health.bo.Doctor;
import com.mp.health.common.Constants;
import com.mp.health.form.JsonObject;
import com.mp.health.form.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author vannh
 */
public class Authenticate extends ActionSupport{
    private final String INDEX_PAGE = "index";
    private String abc;
    private JsonObject json = new JsonObject();
    private String username;
    private String password;

    public JsonObject getJson() {
        return json;
    }

    public void setJson(JsonObject json) {
        this.json = json;
    }

    public void setAbc(String abc) {
        this.abc = abc;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String index() throws Exception{
        HibernateUtils h = HibernateUtils.getInstance();
        String a = FileUtils.getClassPath();
        Session session = h.getCurrentSession("default session");
        Criteria cri = session.createCriteria(Doctor.class);
        List l = cri.list();
        session.close();
        return INDEX_PAGE;
    }
    
    public String test(){
        
        for(int  i = 0; i < 100000; i++)
            System.out.println("test");
        
        json.setMessage("test successful !" + abc);
        return "json";
    }
    
    public String login(){
        if(username != null && password != null && username.equals("vannh4") 
                && password.equals("123456a@")){
            User user = new User();
            user.setUsername(username);
            user.setBirthDay("22/12/1989");
            user.setIsValid(true);
            ActionContext action = ActionContext.getContext();
            action.getSession().put(Constants.USER_INFOR_SESSION, user);
            return INDEX_PAGE;
        } else {
            return "login";
        }
    }
}
